﻿using Microsoft.AspNetCore.Mvc;
using Estsh.Core.Wms.IServices;
using Estsh.Core.Model.Result;
using Estsh.Core.Util;
using Microsoft.AspNetCore.Http;
using Estsh.Core.Models;
using Estsh.Core.Model.Extend.Models;
using Microsoft.AspNetCore.Authorization;
using Estsh.Core.Controllers;
using Newtonsoft.Json;
using Estsh.Core.Model.Extend;
using Estsh.Core.Model.Extend.Models;


namespace Estsh.Core.Web.Plugin.Wms.Areas.wms.Controllers.NC
{
	[Route("wms/[controller]")]
	[ApiController]
	public class NCMoveController : Controller
	{
		private INCMoveService service;

		// GET: LoginController
		public NCMoveController(INCMoveService _service)
		{
			service = _service;
		}

		[HttpPost("index")]
		public IActionResult Index()
		{
			return View();
		}


		/// <summary>
		/// 判断库位
		/// </summary>
		/// <returns>工厂代码1002</returns>
		[HttpPost("CheckLocateName")]
		public IActionResult CheckLocateName(Newtonsoft.Json.Linq.JObject jobj)
		{
			string loginId = jobj["loginId"].ToString().Trim();
			string locateName = jobj["locateName"].ToString().Trim();
			string isPack = jobj["isPack"].ToString().Trim();
			WmsResponseResult result = new WmsResponseResult();
			try
			{
				string obj = service.CheckLocateName(loginId, locateName, isPack);

				result.Success = true;
				result.Data = obj;
			}
			catch (Exception ex)
			{
				result.Msg = ex.Message;
			}
			return Json(result);
		}

		/// <summary>
		/// 执行移库操作
		/// </summary>
		/// <param name="jobj"></param>
		/// <returns></returns>
		[HttpPost("CheckNCMove")]
		public IActionResult CheckNCMove(Newtonsoft.Json.Linq.JObject jobj)
		{
			string loginId = jobj["loginId"].ToString().Trim();
			string locateName = jobj["locateName"].ToString().Trim();
			string isPack = jobj["isPack"].ToString().Trim();
			string cartonNo = jobj["cartonNo"].ToString().Trim();
			WmsResponseResult result = new WmsResponseResult();
			try
			{
				string obj = service.CheckNCMove(loginId, cartonNo, locateName, isPack);

				result.Success = true;
				result.Data = obj;
			}
			catch (Exception ex)
			{
				result.Msg = ex.Message;
			}
			return Json(result);
		}

		[HttpPost("GetNCMovePartInfo")]
		public IActionResult GetNCMovePartInfo(Newtonsoft.Json.Linq.JObject jobj)
		{
			string isPack = jobj["isPack"].ToString().Trim();
			string cartonNo = jobj["cartonNo"].ToString().Trim();
			WmsResponseResult result = new WmsResponseResult();
			try
			{
				List<SysStock> obj = service.GetNCMovePartInfo(cartonNo, isPack);

				result.Success = true;
				result.Data = obj;
			}
			catch (Exception ex)
			{
				result.Msg = ex.Message;
			}
			return Json(result);
		}



	}
}
